package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import bot.City;
import bot.PageGenerator;
import bot.Util;

public class GeoSentenceButton extends JButton{

	/**
	 * Default Serialization
	 */
	private static final long serialVersionUID = 1L;
	private JTextField url;
	private JTextField date;
	private PageGenerator page;
	
	public GeoSentenceButton(JTextField textCity, JTextField textDate){
		super("Geography Sentence");
		url = textCity;
		date = textDate;
		page = new PageGenerator();
		
		addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg) {
				try{
					//make sure input is valid
					if (url.getText().equals("")){
						throw new IllegalArgumentException();
					}
					City choosen = new City(url.getText(), BotGui.data);
					//put the population info in the paste buffer
					Util.setPasteBuffer(page.getGeoSentence(choosen, date.getText()));
				}
				catch (IllegalArgumentException e){
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "Invaild city name");
				}
			}
		});
	}
}
